package com.slunk.platforms;

import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.utils.Array;

public class SDialogueDecision extends SRenderableNode {
	SLabel questionObject;
	Array<SLabel> choicesArray;
	Sprite backgroundIndicator;
	int choiceIndex;
	
	public SDialogueDecision(Sprite backgroundIndicator, String questionString, String[] answers) {
		choiceIndex = 0;
		choicesArray = new Array<SLabel>();
		this.questionObject = new SLabel(questionString, 100,100);
		int mul = 1;
		for (String answer : answers) {
			choicesArray.add(new SLabel(answer, 100, 100 - mul * 25));
			mul = mul + 1;
		}
		this.backgroundIndicator = backgroundIndicator;
	}
	
	public SDialogueDecision(Sprite backgroundIndicator, String questionString, String trueString, String falseString) {
		this(backgroundIndicator,questionString,new String[]{trueString, falseString});
	}

	public void drawObject(SpriteBatch batch) {
		questionObject.drawSelf(batch);
		for (SLabel choiceObject : choicesArray) {
			choiceObject.drawSelf(batch);
		}
		TextBounds selectedBounds = choicesArray.get(choiceIndex).getBounds();
		backgroundIndicator.setBounds(choicesArray.get(choiceIndex).x, choicesArray.get(choiceIndex).y, selectedBounds.width, -selectedBounds.height);
		backgroundIndicator.draw(batch);
	}
	
	public void moveUp() {
		if ( (choiceIndex - 1) >= 0 ) {
			choiceIndex = choiceIndex - 1;
		}
	}
	
	public void moveDown() {
		if ((choiceIndex + 1) <= (choicesArray.size - 1)) {
			choiceIndex = choiceIndex + 1;
		}
	}
	
	public void moveTo(int choiceIndex) {
		if (choiceIndex <= choicesArray.size - 1 && choiceIndex > -1) {
			this.choiceIndex = choiceIndex;
		}
	}
	
	public int mousePositionOver(float x, float y) {
		for (int i = 0; i < choicesArray.size; i++) {
			if (choicesArray.get(i).containsMousePosition(x, y)) {
				return i;
			}
		}
		return -1;
	}
	
	@Override
	public int compareTo(SRenderableNode arg0) {
		// TODO Auto-generated method stub
		return 0;
	}
}
